package com.heima.hoteldemo.mq;

import com.heima.hoteldemo.constants.MqConstants;
import com.heima.hoteldemo.service.IHotelService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author li
 * 监听消息
 */
@Component
public class HotelListener {
    @Autowired
    private IHotelService hotelService;

    /**
     * 监听酒店新增或修改的业务
     */
    @RabbitListener(queues = MqConstants.HOTEL_INSERT_QUEUE)
    public void listenHotelInsertOrUpdate(Long id) {
        hotelService.insertById(id);
        System.out.println("酒店数据更新成功，id为：" + id);
    }

    /**
     * 监听酒店删除的业务
     */
    @RabbitListener(queues = MqConstants.HOTEL_DELETE_QUEUE)
    public void listenHotelDelete(Long id) {
        hotelService.deleteById(id);
        System.out.println("酒店数据删除成功，id为：" + id);
    }

}
